package spring.superrun.record.mvc.setup;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import spring.superrun.record.mvc.Aop.AuthenticationInterceptor;

/**
 * @author haoboyuan
 * @Date 2021年6月18日
 * 配置类
 */
@Configuration //表示当前类是配置相关的
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 跳转方式为：转发; 第一个参数为路径, 第二个参数为视图路径名称
        registry.addViewController("/").setViewName("/index.html");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthenticationInterceptor())
                //被拦截的路径
                .addPathPatterns("/**")
                //拦截白名单
                .excludePathPatterns(
                        "/auth/login",
                        "/auth/join",
                        "/auth/tojoin",
                        "/auth/tologin",
                        "/auth/logout"
                        ,"/**/**.js", "/**/*.css"
                        , "/**/*.png ", "/**/*.jpg"
                        , "/**/*.gif ",
                        "/**/*.html",
                        "/**/*.woff",
                        "/**/*.woff2",
                        "/**/*.ttf",
                        "/swagger-ui");
    }
    @Bean
    public AuthenticationInterceptor authenticationInterceptor(){
        return  new AuthenticationInterceptor();
    }
}
